package com.jason.game.online

import android.os.Bundle
import android.view.View
import android.widget.EditText
import androidx.viewpager.widget.ViewPager
import com.cby.library.common.adapter.CommonViewPagerAdapter
import com.cby.library.common.base.BaseActivity
import com.cby.library.common.ext.afterTextChange
import com.cby.library.common.ext.showToast
import com.cby.library.common.ext.start
import com.cby.library.tool.util.CbyLogUtils
import com.google.android.material.tabs.TabLayout
import com.jason.game.online.home.HomeFragment
import java.io.File


class MainActivity : BaseActivity() {

    private lateinit var mainPager: ViewPager
    private lateinit var bottomLayout: TabLayout

    override fun beforeViewInit() {
        CbyLogUtils.flog("测试数据")
    }

    override fun getLayoutId() = R.layout.activity_main

    override fun initView() {
        mainPager = findViewById(R.id.vp_main_container)
        mainPager.offscreenPageLimit = 5
        bottomLayout = findViewById(R.id.bottom_nav)

        mainPager.addOnPageChangeListener(
            TabLayout.TabLayoutOnPageChangeListener(bottomLayout)
        )

        MainBottomNav.setBottomTabs(bottomLayout, layoutInflater)
        bottomLayout.addOnTabSelectedListener(
            object : TabLayout.ViewPagerOnTabSelectedListener(mainPager) {
                override fun onTabSelected(tab: TabLayout.Tab) {
                    mainPager.currentItem = tab.position
                }


                override fun onTabReselected(tab: TabLayout.Tab?) {

                }
            })
    }

    override fun onDataInit() {
        val pagerAdapter = CommonViewPagerAdapter(
                supportFragmentManager
            ).apply {
            this.addFragment(HomeFragment(), getString(R.string.wan_home_title))
            this.addFragment(HomeFragment(), getString(R.string.wan_project_title))
            this.addFragment(HomeFragment(), getString(R.string.wan_square_title))
            this.addFragment(HomeFragment(), getString(R.string.wan_public_title))
            this.addFragment(HomeFragment(), getString(R.string.wan_my_title))
        }

        mainPager.adapter = pagerAdapter
        mainPager.currentItem = 0
    }

}